package admin

import (
	"context"

	"go-zero-mall/app/admin/cmd/api/internal/svc"
	"go-zero-mall/app/admin/cmd/api/internal/types"
	"go-zero-mall/app/admin/cmd/rpc/pd"
	"go-zero-mall/common/ctxdata"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type UmsAdminInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUmsAdminInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UmsAdminInfoLogic {
	return &UmsAdminInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UmsAdminInfoLogic) UmsAdminInfo(req *types.InfoReq) (resp *types.InfoResp, err error) {
	userId := ctxdata.GetUidFromCtx(l.ctx)
	in := pd.AdminInfoReq{
		Id: userId,
	}
	d, err := l.svcCtx.AdminRpc.AdminInfo(l.ctx, &in)
	if err != nil {
		return nil, err
	}
	var info types.InfoResp
	copier.Copy(&info, d)
	return &info, nil
}
